<?php
/**
 * User: Hunman
 * Date: 14.07.13
 * Time: 15:28
 */
class Model_Default extends Model_Model
{

    private $pagination = array(
        "Category" => array(
            "table" => "Tovar_cat",
            "column" => "cat"
        ),
        "Podcategory"=> array(
            "table" => "Tovar_cat",
            "column" => "podcat"
        )
    );
    function __construct()
    {
//        $this->getContent();
    }



    function pagination($inCameDate, $id)
    {
        $id = (int) $id;
        if (array_key_exists($inCameDate, $this->pagination))
        {
            $sql = <<<SQL
                      SELECT
                            count(*)
                      FROM
                            {$this->pagination["$inCameDate"]["table"]}
                      WHERE
                            {$this->pagination["$inCameDate"]["column"]} = $id
SQL;
            $result = $this->cache($sql);
            if ($result == null)
            {
                $db = $this->dbh();
                $stmt = $db->query($sql);
                $result = $stmt->fetch(PDO::FETCH_COLUMN);
                //запись в кеш
                $this->cache($sql, $result, 3600*24/*сутки*/);
            }
            return $result;

        }
        return false;
    }
}